package org.advanced.sentinel;

import redis.clients.jedis.JedisSentinelPool;

import java.util.HashSet;
import java.util.Set;

/**
 * @author John.zhang
 * @version Id: JedisSentinel, v 1.0 2020/12/23 19:42 ZhiYong Exp $
 * 连接哨兵
 */
public class JedisSentinel {
    private static JedisSentinelPool pool;

    private static JedisSentinelPool createJedisPool() {
        // master的名字是sentinel.conf配置文件里面的名称
        String masterName = "redis-master";
        Set<String> sentinels = new HashSet<String>();
        sentinels.add("10.181.144.255:26379");
        sentinels.add("10.181.144.255:26379");
        sentinels.add("10.181.144.255:26379");
        pool = new JedisSentinelPool(masterName, sentinels);
        return pool;
    }

    public static void main(String[] args) {
        JedisSentinelPool pool = createJedisPool();
        pool.getResource().set("John", "qq"+System.currentTimeMillis());
        System.out.println(pool.getResource().get("John"));
    }
}
